<?php
/*
 * Created on 14.04.2007
 * @filesource: mod_extensionicons.php
 * @author: Nikolai Plath
 */

defined( '_VALID_MOS' ) or die ( 'Direct Access to this script is not allowed' );

define ( 'SPACERCHAR' , ' | ' );

global $mosConfig_lang;

//get the language
if (file_exists($mosConfig_absolute_path .'/administrator/components/com_extensionicons/language/'.$mosConfig_lang.'.php')) {
	require_once ($mosConfig_absolute_path .'/administrator/components/com_extensionicons/language/'.$mosConfig_lang.'.php');
} else {
	require_once ($mosConfig_absolute_path .'/administrator/components/com_extensionicons/language/english.php');
}

//////////////
/*
 * acl_check
 * we grant access only to Admin and Super Admin - does anyone have a better solution ????
 */
//if ( $acl->acl_check( 'administration', 'manage', 'users', $my->usertype, 'components', $row->linkoption ) )
//echo $my->usertype."<br />AAA: ".$row->linkoption." aa: ".$my->usertype." XXXX: ".$acl->acl_check( 'administration', 'manage', 'users', $my->usertype, 'components', $row->linkoption );
if ( $my->usertype == "Administrator"
	| $my->usertype == "Super Administrator")
{
/////////////

//if the mainmenu gets disabled we also "hide" to prevent pagelocks
if (
	( isset ( $_GET['hidemainmenu'] ) && $_GET['hidemainmenu'] == 1 )
	|
	( isset ( $_POST['hidemainmenu'] ) && $_POST['hidemainmenu'] == 1 )
	)
{
	echo _EXICONS_DISABLED;
} else
{
	global $database;
	$showdiv = intval( $params->get( 'showdiv', 1 ) );
	$database->setQuery("SELECT * FROM #__extension_icons"
						. "\n WHERE published = 1"
					    . "\n ORDER BY ordering");
	$rows = $database->loadObjectList();

	foreach ( $rows as $row )
	{
		if ( $showdiv )
		{
			echo '<div>';
		}

		echo '<a href="' . $mosConfig_live_site . '/administrator/index2.php?'
		 . $row->admin_menu_link . '">'
		 . '<img src="' . $mosConfig_live_site . '/includes/' . $row->admin_menu_img . '"'
		 . ' align="middle" border="0"'
		 . ' alt="' . $row->admin_menu_alt . '"'
		 . ' title="' . $row->admin_menu_alt . '"'
		 . ' /></a>';

		echo ( $showdiv ? '</div>' : '&nbsp;' );

	}//foreach

	echo SPACERCHAR;

	/*
	 * External Preview
	 */
	if ( $params->get ( 'showexternalpreview' ) )
	{
		echo  '<a href="' . $mosConfig_live_site .'" target="_blank">'
			. '<img src="../includes/js/ThemeOffice/preview.png" align="middle" border="0"'
			. ' alt="External Preview"'
			. ' title="External Preview" />'
			. '</a>';
		
		echo SPACERCHAR;
	}

	/*
	 * Unread Messages
	 */
	if ( $params->get ( 'showunread' ) )
	{
		$query = "SELECT COUNT(*)"
		. "\n FROM #__messages"
		. "\n WHERE state = 0"
		. "\n AND user_id_to = " . (int) $my->id;

		$database->setQuery( $query );
		$unread = $database->loadResult();

		if ($unread)
		{
			echo $inboxLink.'<a href="index2.php?option=com_messages" style="color: red; text-decoration: none;  font-weight: bold">'
				 . $unread
				 . '<img src="images/mail.png" align="middle" border="0" alt="Mail" title="Mail" /></a>';
		} else
		{
			echo '<a href="index2.php?option=com_messages" style="color: black; text-decoration: none;">'
				. $unread
				. '<img src="images/nomail.png" align="middle" border="0" alt="Mail" title="Mail" /></a>';
		}
		echo SPACERCHAR;
	}//if show unreadmessages

	/*
	 * Disk space
	 */
	if ( $params->get ( 'showfreediskspace' ) )
	{
		if ( function_exists( 'disk_free_space' ) )
		{
			$options = round( ( disk_free_space( "." ) ) / ( 1024 * 1024 ) );
			if ( $params->def( 'freediskspaceunit' ) == "mb" )
			{
				$options .= " MB";
			} elseif ( $params->def( 'freediskspaceunit') == "gb" )
			{
			 	$options = round( $options / 1024 ) . " GB";
	   		}
		} else
		{
			$options = '-'; //_NO_SUPPORT;
		}
		echo  '<img src="../includes/js/ThemeOffice/backup.png"'
			. ' align="middle" border="0"'
			. ' alt="Disk Space: ' . $options . '"'
			. ' title="Disk Space : ' . $options . '" />';

			if ( $params->get ('showfreediskspacetext') )
			{
				echo $options;
			}
		echo SPACERCHAR;
	}

	/*
	 * Load Values
	 */
	if ( $params->get ( 'showloadvalues' ) )
	{
		preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",@exec('uptime'),$load);
		$options = @$load[1]." - ".@$load[2]." - ".@$load[3];
			echo '<img src="../includes/js/ThemeOffice/statistics.png"'
				. ' align="middle" border="0"'
				. ' alt="Load Values: ' . $options . '"'
				. ' title="Load Values: ' . $options . '" />';
			if ( $params->get ('showloadvaluestext') )
			{
				echo $options;
			}

		echo SPACERCHAR;

	}

	/*
	 * Memory Usage
	 */
	if ( $params->get ( 'showmemoryusage' ) )
	{
		if ( function_exists( 'memory_get_usage' )
			&& function_exists( 'ini_get' ) )
		{
			$memusage = ( memory_get_usage() ) / 1024;
			$options = '';
			if ( $params->def( 'used_mem' , 1 ) )
			{
//				$options .= "\r\n" . _MEMUSAGE . ': '
				$options .= "\r\n Used: \t"
						 . number_format( $memusage , 0 , '' , '.' ) . ' kB';
			}
			if ( $params->def( 'free_mem' , 1 ) )
			{
				$memory = ( ereg_replace( "[A-Za-z]" , "" , ini_get( 'memory_limit' ) ) ) * 1024;
				$freemem = $memory - $memusage;
//				$options .= ' / ' . _FREEMEM . ': '
				$options .= "\r\n Free: "
						 . number_format( $freemem , 0 , '' , '.' ) . ' kB';
			}
		} else
		{
			$options =  '-';//_NO_SUPPORT;
		}
		echo '<img src="../includes/js/ThemeOffice/statistics.png"'
			. ' align="middle" border="0"'
			. ' alt="Memory usage: ' . $options . '"'
			. ' title="Memory usage: ' . $options . '" />';

		if ( $params->get ('showmemoryusagetext') )
		{
			echo $options;
		}
		echo SPACERCHAR;
	}

}//if hidemainmenu

/////
}//if acl_check
/////

//we need
echo '&nbsp;';//some
// space
//...


?>
